package classes.net 
{
	import flash.display.*;
	
	import net.metafor.faceapi.*;
	import net.metafor.faceapi.events.*;
	import by.blooddy.crypto.serialization.*;
	
	/**
	 * ...
	 * @author yanmasharski
	 */
	
	public class DataController {
		
		private var face_api:FaceApi;
		
		public function DataController() {
			face_api = new FaceApi();
			face_api.apiKey = "54df93a9250ff995cc05884af7885b6b";
			face_api.apiSecret = "94634564bded85e4db69da9a4fc4d986";
			
			face_api.recognitionService.addEventListener(FaceEvent.SUCCESS, onUploadAndDetectSuccess);
		}
		
		public function startResearch():void {
			uploadToFaceDotCom();
		}
		
		private function uploadToFaceDotCom():void {
			var tmp_bitmapdata:BitmapData = new BitmapData(Main.two_photos_interface.photo_container_one.width, Main.two_photos_interface.photo_container_one.height);
			tmp_bitmapdata.draw(Main.two_photos_interface.photo_container_one);
			var tmp_bitmap:Bitmap = new Bitmap(tmp_bitmapdata);
			face_api.recognitionService.uploadAndDetect(tmp_bitmap);
		}
		
		private function onUploadAndDetectSuccess(e:FaceEvent):void {
			face_api.recognitionService.removeEventListener(FaceEvent.SUCCESS, onUploadAndDetectSuccess);
			
			var tid:String = e.data.photos[0].tags[0].tid;
			trace(JSON.encode(e.data));
			
			Main.two_photos_interface.drawDebugPoints(e.data.photos[0].tags[0],e.data.photos[0].width, e.data.photos[0].height);
		}
		
	}

}